<template>
  <Dialog title="关联订单" v-model="dialogVisible" class="divide-order-dialog">
    <el-form
      class="-mb-15px"
      :model="orderQueryParams"
      ref="queryOrderFormRef"
      :inline="true"
      label-width="80px"
    >
      <el-form-item label="订单号" prop="orderCode">
        <el-input
          v-model="orderQueryParams.orderCode"
          placeholder="请输入"
          clearable
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="orderList" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="订单类型" align="center" prop="business">
        <template #default="scope">
          {{ (scope.row.business = '001' ? '美发订单' : '到家订单') }}
        </template>
      </el-table-column>
      <el-table-column label="订单号" align="center" prop="orderCode" />
      <el-table-column label="业务发生地" align="center" prop="address" />
      <el-table-column label="业务完成人" align="center" prop="oprName" />
      <el-table-column label="订单营业额（元）" align="center" prop="price">
        <template #default="scope">
          {{ (scope.row.price / 100).toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column label="提成金额" align="center" prop="dividePrice">
        <template #default="scope">
          {{ (scope.row.dividePrice / 100).toFixed(2) }}
        </template>
      </el-table-column>
    </el-table>
    <Pagination
      :total="orderTotal"
      v-model:page="orderQueryParams.pageNo"
      v-model:limit="orderQueryParams.pageSize"
      @pagination="getOrderList"
    />
  </Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import type { UploadProps } from 'element-plus'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'

import { getAccessToken, getTenantId } from '@/utils/auth'
import * as DivideApi from '@/api/meijia/divide'
const url = import.meta.env.VITE_UPLOAD_URL
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  name: undefined
})
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const queryOrderFormRef = ref() // 搜索的表单
const orderList = ref([]) // 订单列表
const orderTotal = ref(0) // 订单列表的总页数
const orderQueryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  orderCode: undefined,
  divideAllCode: undefined
})
/** 打开弹窗 */
const open = async (code: string, userCode: string) => {
  dialogVisible.value = true
  orderQueryParams.divideAllCode = code
  orderQueryParams.userCode = userCode
  getOrderList()
}

const getOrderList = async () => {
  const data = await DivideApi.getOrderUserDetailRespVOPage(orderQueryParams)
  orderList.value = data.list
  orderTotal.value = data.total
}
/** 搜索按钮操作 */
const handleQuery = () => {
  orderQueryParams.pageNo = 1
  getOrderList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryOrderFormRef.value.resetFields()
  handleQuery()
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
<style scoped>
.divide-order-dialog {
  height: 70%; /* 设置您想要的固定高度 */
  overflow-y: auto; /* 对话框内容超出固定高度时自动显示滚动条 */
}
</style>
